﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Data;
using System.Data.SqlClient;

namespace Web2014112110
{
    public partial class Register : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            this.Title = "注册登录账号界面";
        }

        protected void btnAdd_Click(object sender, EventArgs e)
        {
            string strCn = "server=pc.hstc.cn;database=dhd2014112110;uid=2014112110;pwd=19941225";
            SqlConnection cn = new SqlConnection(strCn);
            try
            {
                if (this.RadioButton1.Checked)
                {
                    cn.Open();
                    string strSql = "INSERT INTO TeaInfo(Account, Password,Gender, Age, Place,Nation,email) VALUES   (N'" + this.txtAccount.Text + "',N'" + this.txtPassword.Text + "',N'女'," + this.txtAge.Text + ",N'" + this.txtPlace.Text + "',N'" + this.txtNation.Text + "',N'" + this.txtemail.Text + "')";
                    SqlCommand cmd = new SqlCommand(strSql, cn);
                    int iUpd = cmd.ExecuteNonQuery();
                    if (iUpd < 1)
                    {
                        this.lblInfo3.Text = "新增失败，此用户名已存在！";
                    }
                    else
                    {
                        this.lblInfo3.Text = "新增成功！";
                    }
                }
                if(this.RadioButton2.Checked){
                    cn.Open();
                    string strSql = "INSERT INTO TeaInfo(Account, Password,Gender, Age, Place,Nation,email) VALUES   (N'" + this.txtAccount.Text + "',N'" + this.txtPassword.Text + "',N'男'," + this.txtAge.Text + ",N'" + this.txtPlace.Text + "',N'" + this.txtNation.Text + "',N'" + this.txtemail.Text + "')";
                    SqlCommand cmd = new SqlCommand(strSql, cn);
                    int iUpd = cmd.ExecuteNonQuery();
                    if (iUpd < 1)
                    {
                        this.lblInfo3.Text = "注册失败！";
                    }
                    else
                    {
                        this.lblInfo3.Text = "成功注册" + iUpd.ToString() + "条记录！";
                    }
                }
            }
            catch(Exception ex)
            {
                this.lblInfo3.Text = ex.Message;
            }
            finally
            {
                cn.Close();
            }
        }
        protected void Page_PreInit(object sender, EventArgs e)
        {
            Page.Theme = "ThemeFour";
        }
    }
}